<template>
  <div class="app-container">
    <Search-content :queryParams="queryParams" labelWidth="120px" @query="handleQuery" @reset="resetQuery">
      <el-col :span="6">
        <el-form-item label="车牌号:">
          <el-input v-model.trim="queryParams.carNo" :maxlength="30" clearable placeholder="请输入车牌号" />
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="车架号:">
          <el-input v-model.trim="queryParams.vinNo" :maxlength="30" clearable placeholder="请输入车架号" />
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="品牌/车系/车型:">
          <linkage-select @changeNode="linkageChange" v-model="linkageList" placeholder="请选择品牌/车系/车型" />
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="客户名称:">
          <el-input v-model.trim="queryParams.customerName" :maxlength="30" clearable placeholder="请输入客户名称" />
        </el-form-item>
      </el-col>

      <el-col :span="6">
        <el-form-item label="维修单:">
          <el-input v-model.trim="queryParams.maintenanceNo" :maxlength="30" clearable placeholder="请输入维修单" />
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="车辆产权城市:">
          <el-input v-model.trim="queryParams.propertyRightName" :maxlength="30" clearable placeholder="请输入车辆产权城市" />
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="创建人:">
          <el-input v-model.trim="queryParams.createBy" :maxlength="30" clearable placeholder="请输入创建人" />
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="创建时间:">
          <el-date-picker v-model="valueDate" type="daterange" placeholder="请选择日期" range-separator="-" @change="handleTime" value-format="yyyy-MM-dd" start-placeholder="开始日期" end-placeholder="结束日期" style="width: 100%" />
        </el-form-item>
      </el-col>
    </Search-content>

    <div class="card-wrap card-padding">
      <div class="table-title-wrap justify-end">
        <el-button size="mini" v-hasPermi="['scrapHandle:scrapHandleList:new']" @click="handleNew" type="primary">新增申请 </el-button>

        <el-button size="mini" v-hasPermi="['scrapHandle:scrapHandleList:derive']" @click="handleDerive" type="primary">导出 </el-button>
      </div>

      <table-page :loading="loading" :dataList="dataList" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @setSizeCurrent="handleList" border>
        <template slot="tableColAc">
          <el-table-column label="操作" align="center" fixed="left" width="150">
            <template #default="{ row }">
              <el-button size="mini" type="text" @click="handleView(row, 'view')" v-hasPermi="['scrapHandle:scrapHandleList:view']"> 查看 </el-button>
              <!-- 自动-->
              <el-button size="mini" type="text" @click="handleDisposal(row)" v-if="[0, 3].includes(Number(row.auditStatus)) && Number(row.source) === 0" v-hasPermi="['scrapHandle:scrapHandleList:disposal']"> 处置车辆 </el-button>
              <!-- 手动-->
              <el-button size="mini" type="text" @click="handleDisposalNew(row)" v-if="Number(row.auditStatus) === 3 && Number(row.source) === 1" v-hasPermi="['scrapHandle:scrapHandleList:disposal']"> 处置车辆 </el-button>
            </template>
          </el-table-column>
        </template>

        <template slot="tableCol">
          <el-table-column align="center" label="报废处置编号" min-width="220" show-overflow-tooltip prop="vehicleDisposalScrapNo" />

          <el-table-column align="center" label="车牌号" min-width="140" show-overflow-tooltip prop="carNo" />

          <el-table-column align="center" label="客户名称" min-width="160" show-overflow-tooltip prop="customerName" />

          <el-table-column align="center" label="车架号" min-width="180" show-overflow-tooltip prop="vinNo" />

          <el-table-column label="品牌/车型/车款" show-overflow-tooltip min-width="400">
            <template #default="{ row }"> {{ row.brandName }}{{ row.seriesName }}{{ row.modelName }} </template>
          </el-table-column>

          <el-table-column align="center" label="车辆产权城市" min-width="140" show-overflow-tooltip prop="propertyRightName" />

          <el-table-column align="center" label="车辆归属城市" min-width="140" show-overflow-tooltip prop="ascription" />

          <el-table-column align="center" label="审核节点" min-width="140" show-overflow-tooltip prop="auditTask">
            <template #default="{ row }">
              {{ row.auditTask || '-' }}
            </template>
          </el-table-column>

          <el-table-column align="center" label="审核状态" show-overflow-tooltip min-width="130">
            <template #default="{ row }">
              {{ row.auditFlowStatus || '-' }}
            </template>
          </el-table-column>

          <el-table-column align="center" label="维修单" show-overflow-tooltip min-width="130">
            <template #default="{ row }">
              {{ row.maintenanceNo || '-' }}
            </template>
          </el-table-column>

          <el-table-column align="center" label="理赔承担方式" min-width="140" show-overflow-tooltip prop="claimsMethod">
            <template #default="{ row }">
              {{ row.claimsMethod == 1 ? '客户理赔款' : '保险理赔款' }}
            </template>
          </el-table-column>

          <el-table-column align="center" label="事故还车时间" show-overflow-tooltip min-width="130" prop="returnTime">
            <template #default="{ row }">
              {{ row.returnTime ? $dayjs(row.returnTime).format('YYYY-MM-DD') : '-' }}
            </template>
          </el-table-column>

          <el-table-column align="center" label="财务审批通过时间/收款时间" show-overflow-tooltip min-width="200" prop="compulsoryStartTime">
            <template #default="{ row }">
              {{ row.financialPassedTime ? $dayjs(row.financialPassedTime).format('YYYY-MM-DD') : '-' }}
            </template>
          </el-table-column>

          <el-table-column align="center" label="创建人" show-overflow-tooltip min-width="120" prop="createBy" />

          <el-table-column align="center" label="创建时间" show-overflow-tooltip min-width="130" prop="createTime">
            <template #default="{ row }">
              {{ row.createTime ? $dayjs(row.createTime).format('YYYY-MM-DD') : '-' }}
            </template>
          </el-table-column>
        </template>
      </table-page>
    </div>
  </div>
</template>

<script>
import LinkageSelect from '@/views/components/linkageSelect.vue'
import SearchContent from '@/components/SearchContent/index.vue'
import { getList } from '@/api/vehicleDisposal/scrapHandle.js'

export default {
  name: 'ScrapHandleList', //报废处置处理
  components: {
    SearchContent,
    LinkageSelect,
  },
  computed: {},
  watch: {},
  data() {
    return {
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        carNo: '',
        vinNo: '',
        brandName: '',
        seriesName: '',
        modelName: '',
        customerName: '',
        createBy: '',
        startTime: '',
        endTime: '',
      },
      linkageList: [],
      dataList: [],
      total: 0,
      loading: false,
      valueDate: [],
    }
  },
  created() {
    this.handleList()
  },
  activated() {
    this.handleList()
  },
  methods: {
    handleTime(val) {
      if (val) {
        this.queryParams.startTime = val[0]
        this.queryParams.endTime = val[1]
        console.log(this.queryParams.startTime, '-=-=-=-=')
        console.log(this.queryParams.endTime, '-=-=-=-=')
      }
    },

    handleQuery() {
      this.queryParams.pageNum = 1
      this.handleList()
    },

    resetQuery() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        carNo: '',
        vinNo: '',
        brandName: '',
        seriesName: '',
        modelName: '',
        customerName: '',
        createBy: '',
        startTime: '',
        endTime: '',
      }
      this.linkageList = []
      this.valueDate = []
      this.handleList()
    },

    linkageChange(val) {
      this.linkageList = val
      if (val) {
        this.queryParams.brandName = val[0] ? val[0].name : ''
        this.queryParams.seriesName = val[1] ? val[1].name : ''
        this.queryParams.modelName = val[2] ? val[2].name : ''
      } else {
        this.queryParams.brandName = ''
        this.queryParams.seriesName = ''
        this.queryParams.modelName = ''
      }
      this.$forceUpdate()
    },

    //列表
    async handleList() {
      this.loading = true
      try {
        const res = await getList(this.queryParams)
        this.dataList = res.rows
        this.total = res.total
      } catch (e) {
        console.error('获取失败', e)
      } finally {
        this.loading = false
      }
    },

    //新增申请
    handleNew() {
      this._toPage({
        path: '/VehicleDisposal/ScrapDisposal/ScrapHandleNew',
        name: 'ScrapHandleNew',
        query: {
          type: 'edit',
        },
      })
    },

    //导出
    handleDerive() {
      this.download(
        '/vehicleDisposal/vehicleDisposalScrap/export',
        {
          ...this.queryParams,
        },
        `处置报废列表_${new Date().getTime()}.xlsx`
      )
    },

    //查看
    handleView(row) {
      this._toPage({
        path: '/VehicleDisposal/ScrapDisposal/ScrapHandleDetails',
        name: 'ScrapHandleDetails',
        query: {
          type: 'view',
          id: row.vehicleDisposalScrapId,
          flowId: row.flowId,
        },
      })
    },

    //
    handleDisposal(row) {
      this._toPage({
        path: '/VehicleDisposal/ScrapDisposal/ScrapHandleDisposalResultDetails',
        name: 'ScrapHandleDisposalResultDetails',
        query: {
          type: 'edit',
          id: row.vehicleDisposalScrapId,
        },
      })
    },

    handleDisposalNew(row) {
      this._toPage({
        path: '/VehicleDisposal/ScrapDisposal/ScrapHandleNew',
        name: 'ScrapHandleNew',
        query: {
          type: 'edit',
          id: row.vehicleDisposalScrapId,
          flowId: row.flowId,
        },
      })
    },
  },
}
</script>

<style scoped lang=""></style>
